#!/usr/bin/env perl
use strict;
use FindBin;
use Getopt::Long;

sub usage {
    my $pname = $FindBin::Script;

    print("Usage: $pname --name ContanerName\n");
    print("\n");
    print("       --name:    ContainerName\n");

    exit(-1);
}

sub main {
    my ( $name, $image, $tagname, $ports , $network );

    GetOptions(
        'name:s'    => \$name
    );

    if ( not defined($name) )
    {
        usage();
    }

    my $isRoot = 0;
    if ( $< == 0 ) {
        $isRoot = 1;
    }
   
    my $cmd = qq{docker start "$name"};
    if ( $isRoot == 1 ) {
        $cmd = "sudo " . $cmd;
    }

    print("INFO: Execute->$cmd\n");
    my $ret = system($cmd );
    $ret = $ret >> 8;

    if ( $ret eq 0 ) {
        print("INFO: Docker start success.\n");
    }
    else {
        print("ERROR: Docker start failed, container:$name not exists.\n");
    }

    return ($ret);
}

exit main();
